﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microhard.WST.BI.Buz.Interfaces;
using Microhard.WST.BI.Buz.DataAccess;
using Microhard.WST.BI.Buz.Models;
using Microhard.WST.BI.Buz.DTO;

namespace Microhard.WST.BI.Buz.Impls
{
    public class OrderPrdDetailImpl : IOrderPrdDetail
    {
        public Core.DBUtility.ExecutedResult Add(OrderPrdDetailModel model)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Update(OrderPrdDetailModel model)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Delete(List<Guid> ids)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ExecutedResult Delete(OrderPrdDetailModel model)
        {
            throw new NotImplementedException();
        }

        public OrderPrdDetailModel GetModelByID(Guid id)
        {
            throw new NotImplementedException();
        }

        public OrderPrdDetailModel GetModelByModel(OrderPrdDetailModel model)
        {
            throw new NotImplementedException();
        }

        public List<OrderPrdDetailModel> Query(OrderPrdDetailModel Model, int pageIndex, int pageSize, out int totalCount)
        {
            DBEntities db = new DBEntities();

            IEnumerable<PM_OrderPrdDetail> entities = from b in db.PM_OrderPrdDetail
                                                      select b; ;
            if (!string.IsNullOrEmpty(Model.QueryDeliveryCode))
            {
                entities = from b in db.PM_OrderPrdDetail
                           where b.PM_Order.DeliveryCode == Model.QueryDeliveryCode
                           select b;

            }
            totalCount = entities.Count();
            var pagedEntities = entities.OrderByDescending(p => p.PM_Order.DeliveryCode).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            if (pagedEntities != null && pagedEntities.Count > 0)
                return pagedEntities.Select(m => m.ToModel()).ToList();
            return new List<OrderPrdDetailModel>();
        }

        public List<OrderPrdDetailModel> Query(OrderPrdDetailModel Model)
        {
            throw new NotImplementedException();
        }

        public Core.DBUtility.ScopeResult scope
        {
            set;
            get;
        }
    }
}
